﻿using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace sqlmanagewpf
{
    class ViewModels
    {
    }

    public class ServerInfo
    {
        public int Id { get; set; }
        public string ServerType { get; set; }
        public string Server { get; set; }
        public string UserName { get; set; }
        public string Password { get; set; }
        public string Database { get; set; }
    }
    public class DatabaseInfo
    {
        public string Database { get; set; }
        public string crdate { get; set; }


    }

    public class DatabaseConfig : INotifyPropertyChanged
    {
        private string _server;
        private string _serverType;
        private string _userName;
        private string _password;
        private string _database;

        public string Server
        {
            get => _server;
            set
            {
                if (_server != value)
                {
                    _server = value;
                    OnPropertyChanged(nameof(Server));
                }
            }
        }

        public string ServerType
        {
            get => _serverType;
            set
            {
                if (_serverType != value)
                {
                    _serverType = value;
                    OnPropertyChanged(nameof(ServerType));
                }
            }
        }

        public string UserName
        {
            get => _userName;
            set
            {
                if (_userName != value)
                {
                    _userName = value;
                    OnPropertyChanged(nameof(UserName));
                }
            }
        }

        public string Password
        {
            get => _password;
            set
            {
                if (_password != value)
                {
                    _password = value;
                    OnPropertyChanged(nameof(Password));
                }
            }
        }

        public string Database
        {
            get => _database;
            set
            {
                if (_database != value)
                {
                    _database = value;
                    OnPropertyChanged(nameof(Database));
                }
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void OnPropertyChanged(string propertyName)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }

    public static class ObservableCollectionExtensions
    {
        public static void Sort<T>(this ObservableCollection<T> collection, Func<T, object> keySelector)
        {
            var sortedList = collection.OrderBy(keySelector).ToList();

            collection.Clear();
            foreach (var item in sortedList)
            {
                collection.Add(item);
            }
        }
    }



    public class TreeNodeConfig : BindableBase, INotifyPropertyChanged
    {
        public long Id { get; set; }

        private string _name;
        public string Name
        {
            get { return _name; }
            set
            {
                if (_name != value)
                {
                    _name = value;
                    RaisePropertyChanged(nameof(Name));
                }
            }
        }
        public TreeNodeConfig Father { get; set; }

        public ObservableCollection<TreeNodeConfig> Children { get; set; }

        private bool _isExpanded;

        public bool IsExpanded
        {
            get { return _isExpanded; }
            set
            {
                if (_isExpanded != value)
                {
                    _isExpanded = value;
                    RaisePropertyChanged(nameof(IsExpanded));
                }
            }
        }


        private bool isSelected = false;
        public bool IsSelected
        {
            get { return this.isSelected; }
            set
            {
                if (isSelected != value)
                {
                    isSelected = value;
                    RaisePropertyChanged(nameof(IsSelected));
                }
            }
        }

        private bool _isEditable;
        public bool IsEditable
        {
            get { return _isEditable; }
            set
            {
                if (_isEditable != value)
                {
                    _isEditable = value;
                    RaisePropertyChanged(nameof(IsEditable));
                }
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
        protected virtual void RaisePropertyChanged(string propertyName)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }

        public NodeType NodeType { get; set; }
       
    }

    public enum NodeType
    {
        //Folder,
        //Document,
        System,
        Rack,
        table,
        Module,


    }

}
